/*
 * Copyright 2020 www.mytijian.com All right reserved. This software is the
 * confidential and proprietary information of www.mytijian.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with www.mytijian.com.
 */
package com.mytijian.task.task.listener;

import com.mytijian.task.util.IpAddressUtil;
import com.mytijian.task.model.TaskValue;
import com.mytijian.task.repository.TaskRepository;
import com.mytijian.task.model.TaskIdentify;

public class FailoverLogStoreListener implements RuningTaskListener {
    private Integer hasCode = 2;
    private TaskRepository taskRepository;
    public FailoverLogStoreListener(TaskRepository taskRepository) {
        this.taskRepository = taskRepository;
    }
    @Override
    public boolean newTaskIdentify(TaskIdentify taskIdentify, TaskValue taskValue) {
        taskRepository.save(taskIdentify, taskValue, IpAddressUtil.getLocalHost());
        //存迁移日志。
        return true;
    }

    @Override
    public void removeRemoteTaskIdentify(TaskIdentify taskIdentify) {

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof FailoverLogStoreListener)) return false;

        FailoverLogStoreListener that = (FailoverLogStoreListener) o;

        return hasCode.equals(that.hasCode);
    }

    @Override
    public int hashCode() {
        return hasCode.hashCode();
    }
}
